| Miles Sound System SDK 7.2a |
Q: | My sound is skipping on Windows or MacOS X - what can I do? |
A: | Under Win32, Win64 and MacOS X, mixing happens on a background thread (on the other Miles platforms, mixing occurs on an interrupt). Unlike interrupts, threads are subject to starvation - that is, depending on CPU load, one thread can be neglected for a period of time. When that happens to the Miles mixing thread, then the digital audio can "skip" momentarily. Fortunately, on NT-based Windows platforms and fast Macs running Mac OS X, this rarely happens - you really have to try to cause a skip. Unfortunately, on the Windows 9x based platforms and on slower Macs, it is fairly easy to cause the Miles thread to starve. The easiest way to trigger starvation is to do a lot of sustained disk IO on an IDE-based device. So, regardless of the cause of the problem, we just want the user to have a good experience. A simple way to fix the problem is to just mix ahead farther - if we mix ahead 200 milliseconds, then we can tolerate a thread dropout of up to 200 ms with no trouble! The only problem is that now our latency is 200 ms - fine for some games, but terrible for others! Fortunately, there is a good compromise. By using the AIL_get_timer_highest_delay function, you can track the length of the thread starvations as they occur. So, let's say you have a game that skips when you read in the level data from the disk. The best way to fix the problem is something like this: 1) Call AIL_get_timer_highest_delay before you start the I/O (this clears the previous high value). 2) Do all your IO. 3) Call AIL_get_timer_highest_delay and record it. Run your game on a couple machines and keep track of the high value. It's usually going to be something around 150 milliseconds, but get a good reading with your game's pattern of IO. Now we just bump up the latency during the I/O and then bump it back down after - you get the best of both worlds - good latency in the general case, and enough mix ahead to handle the I/O dropouts. Once you know roughly what latency you have to cover, simply do something like this: 1) On Win32/Win64, call AIL_set_preference on DIG_DS_MIX_FRAGMENT_CNT to your highest timer delay divided by 8 (each fragment in Miles is 8 ms on Windows). On MacOS, call AIL_set_preference on DIG_SM_MIX_FRAGMENT_CNT to your highest timer delay divided by 8 (each fragment in Miles is 8 ms on the Mac). 2) Call AIL_serve to make sure that the mix-ahead buffer is filled. 3) Do all your IO. 4) On Win32/Win64, call AIL_set_preference on DIG_DS_MIX_FRAGMENT_CNT to set it back to its default value of 8. On MacOS, call AIL_set_preference on DIG_SM_MIX_FRAGMENT_CNT to set it back to its default value of 8. |
Next Topic (My application is crashing - what should I try?)
Previous Topic (How much latency does Miles have?)
Group:
FAQs and How Tos
Related Sections:
Sharing the CPU under MacOS, Sharing the CPU under Win32, Sharing the CPU under Win64
Related Functions:
AIL_get_timer_highest_delay, AIL_serve, AIL_set_preference
Related Basic Types:
MILES_PREFERENCES
For technical support, e-mail Miles3@radgametools.com
© Copyright 1991-2007 RAD Game Tools, Inc. All Rights Reserved.